export default {
  name: 'newScore',
  components: {
    cityCascader: () => import("../../../component/cityCascader/index.vue")
  },
  data() {
    return {
      form: {
        startdate: '',
        enddate: '',
        province: "",
        city: "",
        area: "",
        pagenum: 1,
        pagesize: 10,
        citys: []
      },
      level: '0',
      tableData: [],
      total: 0,
      loading: false,
      
      totalsum: 0
    }
  },
  created() {
   /* this.form.startdate = this.$route.params.startdate || '';
    this.form.enddate = this.$route.params.enddate || ''; */
    this.getTableData();
  },
  methods: {
    // 选择城市
    handleCityChange(val) {
      this.form.citys = val;
      this.form.province = val[0];
      this.form.city = val[1];
      this.form.area = val[2];
    },
    // 时间比较
    compareDate() {
      let startdate = Date.parse(this.form.startdate);
      let enddate = Date.parse(this.form.enddate);
      if (startdate > enddate) {
        this.$message({
          message: '开始时间不能大于结束时间',
          type: 'error'
        });
        return false;
      } else {
        return true;
      }
    },
    getTableData() {
      if (!this.compareDate()) {
        return
      } else {
        this.loading = true
        this.$axios.$post('/app/v1/platform/summary/newIntegrals', this.form).then(res => {
          this.loading = false;
          if (res.data.message === 'success.') {
            this.tableData = res.data.data.list;
            this.totalsum = res.data.data.totalsum;
            this.total = parseInt(res.data.data.totalnum);
          }
        })
      }
    },
    handleCurrentChange(val) {
      this.form.pagenum = val;
      this.getTableData();
    },
    handleSizeChange(val) {
      this.form.pagenum = 1
      this.form.pagesize = val;
      this.getTableData();
    },
    search() {
      this.form.pagenum = 1;
      this.getTableData();
    },
    exportData() {
      this.$axios({
        method: 'post',
        url: '/app/v1/platform/statistic/newIntegralsOut',
        data: this.form,
        responseType: 'blob'
      }).then(res => {
        this.download(res)
      }).catch((error) => {
        this.$message({
          message: '导出失败',
          type: 'error'
        });
      })
    },
    download(res) {
      if (!res) {
        return
      }
      let bob = new Blob([res.data]);
      let fileName = (res.headers['content-disposition']).split('=')[1];
      fileName = decodeURI(fileName)
      let url = window.URL.createObjectURL(bob)
      let link = document.createElement('a')
      link.style.display = 'none'
      link.href = url
      link.setAttribute('download', fileName)
      document.body.appendChild(link)
      link.click()
    }
  },
  filters: {
    filterNewAddScore: function (value) {
      return '+' + value;
    }
  }
}